﻿using System.Linq;
using DG.Tweening;
using Gp.Scripts.Core;
using QFramework;
using UnityEngine;

namespace Gp.Scripts.GUI {

    public enum UIGroup {
        Main,
        Battle,
        Inventory,
        Interact,
        Trade,
        Colony,
        Map,
        Dialogue,
        Quest,
        Puzzle,
    }



    public static class UIGroupExtend {
        public static readonly UIGroup[] BaseLayerGroup = {UIGroup.Main, UIGroup.Battle};

        public static bool IsBaseLayer(this UIGroup obj) {
            return BaseLayerGroup.Contains(obj);
        }
    }
    
    
    
    public class CanvasGroupParent : MonoBehaviour {
        public UIGroup group;

        private CanvasGroup _group;

        private Tween _tweenerCore;
        
        
        private void Start() {
            _group = this.GetOrAddComponent<CanvasGroup>();
        }


        public void Show() {
            _tweenerCore?.Complete();

            _group.interactable = true;
            _group.blocksRaycasts = true;
            
            _group.transform.localScale = Vector3.one * 1.2f; 
            _tweenerCore = DOTween.Sequence()
                .Insert(0, _group.DOFade(1, .25f))
                .Insert(0, _group.transform.DOScale(1, .25f));
        }

        public void Hide() {
            _tweenerCore?.Complete();
            
            _group.interactable = false;
            _group.blocksRaycasts = false;
            _tweenerCore =_tweenerCore = DOTween.Sequence()
                .Insert(0, _group.DOFade(0, .25f))
                .Insert(0, _group.transform.DOScale(1.2f, .25f));
        }
    }
}